const BASE_URL = 'http://localhost:8080/api';

export const request = (options) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: BASE_URL + options.url,
      method: options.method || 'GET',
      data: options.data || {},
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          reject(res.data);
        }
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
};

// 示例调用
import { request } from '@/utils/request';

const getDebts = () => request({ url: '/debt/settlement' });
const addExpense = (data) => request({ url: '/expense', method: 'POST', data });